package com.hyh.toyshopping.mapper;

import com.hyh.toyshopping.model.Car;
import com.hyh.toyshopping.model.view.CarView;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.toyshopping.mapper
 * @Author:hyhWTX
 * @ClassName:CarMapper
 * @CreateTime:2022年-12月-15日 12:58
 * @Description: TODO (一句话描述以下该类的功能)
 */
@Repository
public interface CarMapper {
    /**
     * 根据用户编号和玩具编号检测某个用户的购物车中是否存在某个玩具
     * @param user_id
     * @param toy_id
     * @return   0 表示不存在   >0存在
     */


    /***
     * @Description: 根据用户编号和玩具编号检测某个用户的购物车中是否存在某个玩具
     * @param car
     * @return int
     */

    @Select("select count(*) from tbl_car where user_id=#{user_id} and toy_id=#{toy_id}")
    public int isExistByCar(Car car);
    /**
     * @Description: 根据用户编号和玩具编号更新购物车中的购买数量
     * @param car
     */

    @Update("update tbl_car set car_count=car_count=#{car_count} where user_id=#{user_id} and toy_id=#{toy_id}")
    public void updateCarCount(Car car);

    @Update("update tbl_car set car_count=#{car_count} where car_id=#{car_id}")
    public void updateCarCountByCarId(@Param("car_id")int car_id, @Param("car_count")int car_count);

    @Insert("insert into tbl_car values(null,#{toy_id},#{car_count},#{user_id})")
    void addCar(Car car);

    @Select("select count(*) from tbl_car where user_id=#{user_id}")
    Integer getCount(int user_id);


    List<CarView> getCarList(Integer user_id);

    @Delete("delete from tbl_car where car_id=#{car_id}")
    void deleteCar(int car_id);


    List<CarView> getPayCarList(int[] car_ids);

    void deleteCarByUserIdAndToyId(@Param("user_id") int user_id,@Param("toy_ids") int[] toy_ids);
}

